/***************************************************************************//**
 * @file     csa37f7x.h
 * @version  V1.0.0
 * @author   cs2040
 * @date     2020-09-26 PM
 * @brief    该文件包含了常用的一些重定义及枚举声明
 * 
 * @copyright Copyright (C) 2020 Chipsea Technologies Corp. All rights reserved.
 ****************************************************************************
 * @attention
 *  硬件平台: CSA37F70 评估板V1.0 \n
 *  SDK版本： CSA37F7X_SDK_1.0.0
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date        <th>Version  <th>Author    <th>Description
 * <tr><td>2020-09-26  <td>1.0.0    <td>Chipsea MCU Group  <td>创建初始版本
 * </table>
 *
 *****************************************************************************/

#ifndef __CSA37F7X_H__
#define __CSA37F7X_H__

// Include external header file.
#include <stdint.h>
#include <string.h>

#ifdef __cplusplus
extern "C" {
#endif



/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Uncomment the line below to expanse the "assert_param" macro in the 
   Standard Peripheral Library drivers code */
/* #define USE_FULL_ASSERT    1 */

/* Exported macro ------------------------------------------------------------*/
#ifdef  USE_FULL_ASSERT

/**
  * @brief  The assert_param macro is used for function's parameters check.
  * @param  expr: If expr is false, it calls assert_failed function which reports 
  *         the name of the source file and the source line number of the call 
  *         that failed. If expr is true, it returns no value.
  * @retval None
  */
  #define ASSERT(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
  void assert_failed(uint8_t* file, uint32_t line);
#else
  #define ASSERT(expr) ((void)0)
#endif /* USE_FULL_ASSERT */

#define     __I     volatile const    /*!< 重定义只读  */
#define     __O     volatile          /*!< 重定义只写  */
#define     __IO    volatile          /*!< 重定义读写  */


#define BIT_MASK(bit_name)							((uint32_t)((1<<(bit_name##_NUM))-1)<<(bit_name##_OFFSET))

//#define ASSERT(expr) ((void)0)  /*!< defines assert function */
    
#define reg_bit_mask_set(reg, bit_name, bit) do{reg &= ~(BIT_MASK(bit_name));reg |= ((uint32_t)(bit))<<(bit_name##_OFFSET);}while(0)
#define reg_bit_mask_reset(reg, bit_name) do{reg &= ~(BIT_MASK(bit_name));}while(0)
#define reg_bit_set(reg, bit_name, bit) do{reg |= ((uint32_t)(bit))<<(bit_name##_OFFSET);}while(0)
#define reg_bit_mask_get(reg, bit_name) ((reg & (BIT_MASK(bit_name)))>> (bit_name##_OFFSET))
#define reg_bit_unread_set(reg, bit_name, bit) do{reg = (bit)<<(bit_name##_OFFSET);}while(0)

#define BIT(X)		((uint32_t)(1)<<(X))            /*!< 移位操作 */
#define ABS(x)  (((x)>0) ? (x) : (0-(x)))           /*!< 绝对值操作 */

/**
* @brief: 错误状态定义                              
*/
typedef enum 
{
    ERROR = 0,                                      /*!< 错误/失败 */
    SUCCESS = !ERROR                                /*!< 正确/成功 */
}error_status_t;

/**
* @brief: 位状态定义                              
*/
typedef enum 
{
    RESET = 0,                                      /*!< 复位 */
    SET = !RESET                                    /*!< 置位 */
}bit_status_t;

/**
* @brief: 使能禁止定义                              
*/
typedef enum 
{
	DISABLE = 0,                                    /*!< 禁止 */
	ENABLE = !DISABLE                               /*!< 使能 */
}enable_state_t;

/**
* @brief: 数据有效性定义                              
*/
typedef enum
{
	INVALID = 0,                                    /*!< 无效 */
    VALID  = !INVALID                               /*!< 有效 */
}result_valid_t;




#ifdef __cplusplus
}
#endif

#endif  //__CSA37F7X_H__


/*** (C) COPYRIGHT 2020 Chipsea Technologies (Shenzhen) Corp. ***/
